package com.sgb.goods.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.swgk.core.R;
import com.swgk.core.recyclerview.secondary.SecondaryEntity;

import java.io.Serializable;

/**
 * 材料菜单选项
 * @author cyj
 */
public class MenuEntity<D> extends SecondaryEntity<D> implements Parcelable, Serializable {

    public String appIconUrl = "https://shigongbang.oss-cn-hangzhou.aliyuncs.com/";
    @SerializedName(value = "id", alternate = {"no", "code"})
    public String id = "";
    @SerializedName("name")
    public String name;
    @SerializedName(value = "appIcon", alternate = {"icon", "image", "icon_img","appImg","img"})
    public String appIcon;
    //单个文字
    public String iconContent;
    @SerializedName("selected")
    public boolean selected;
    @SerializedName("imageResource")
    public int imageResource = R.drawable.null_img_list;
    public int hostImg;
    @SerializedName("parentId")
    public String parentId;
    @SerializedName("url")
    public String url;//本地图标名称
    public String realname;
    public long parentNo;
    public int lev;
    public String simpleName; //地区简写
    public String murl;

    public String getAppIcon() {
        if (appIcon == null) {
            return "";
        } else if (appIcon.contains(appIconUrl)) {
            return appIcon;
        } else {
            return appIconUrl + appIcon;
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.name);
        dest.writeString(this.appIcon);
    }

    public MenuEntity() {
    }

    public MenuEntity(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public MenuEntity(String id, String iconContent, String name) {
        this.id = id;
        this.iconContent = iconContent;
        this.name = name;
    }

    public MenuEntity(String id, String iconContent, String name, String url) {
        this.id = id;
        this.url = url;
        this.name = name;
    }

    public MenuEntity(String name, String appIcon, int imageResource) {
        this.name = name;
        this.appIcon = appIcon;
        this.imageResource = imageResource;
    }

    protected MenuEntity(Parcel in) {
        this.id = in.readString();
        this.name = in.readString();
        this.appIcon = in.readString();
    }

    public static final Parcelable.Creator<MenuEntity> CREATOR = new Parcelable.Creator<MenuEntity>() {
        @Override
        public MenuEntity createFromParcel(Parcel source) {
            return new MenuEntity(source);
        }

        @Override
        public MenuEntity[] newArray(int size) {
            return new MenuEntity[size];
        }
    };

}
